﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ENG.TeachersDiary.Classes
{
  abstract class Result
  {
    public abstract string Title { get; }
    public abstract string Abbr { get; }
    public abstract double Sum { get; }
    public abstract double Weight { get; }
    public double Value
    {
      get
      {
        if (Weight == 0)
          return 0;
        else
          return Sum / Weight;
      }
    }

    private Model.MeanMeaning lastMC;
    private double lastValue = double.NaN;
    public string Display
    {
      get
      {
        if (lastValue != Value)
        {
          lastMC = null;
          double value = this.Value;
          //double diff = double.MaxValue;

          var db = Common.DBConn;
          var mcs = db.MeanMeanings.OrderBy(i => i.MaxMeanValue);
          foreach (var fItem in mcs)
          {
            if (value <= fItem.MaxMeanValue)
            {
              lastMC = fItem;
              break;
            }

          } // foreach (var fItem in mcs)

          lastValue = value;
        }

        return lastMC.Display;
      }
    }

  }
}
